<cfparam name="attributes.skedcode" default="">
<cfparam name="attributes.STARTDATE" default="">
<cfparam name="attributes.sdate" default="">

<cfquery name="getAlt" datasource="#client.company_dsn#">
   SELECT PATTERNCODE, NOOFDAYS
   FROM CLKWSALTPATTERN
   WHERE WORKSKEDCODE = '#attributes.skedcode#'
</cfquery>

<cfset altList ="">
<cfoutput query="getAlt">
    <cfloop from="1" to="#NOOFDAYS#" index="i">
        <cfset altList = ListAppend(altList,"#PATTERNCODE#")>
    </cfloop>
</cfoutput>

<cfscript>
    effdate = attributes.STARTDATE;
    ddate = DateAdd( "d",1,attributes.sdate);
    diff = DateDiff("d",effdate,ddate);
    while ( diff gt 7 )
        diff = diff - 7;
    
    if ( not diff )
        diff = 1;
    sPattern = 	ListGetAt( altList, diff );
</cfscript>

<cfquery name="getSchedule" datasource="#client.company_dsn#">
    SELECT DESCRIPTION, DAYTYPE, PATTERNCODE AS WSCODE, CATEGORY
    FROM CLKWSPATTERN 
    WHERE PATTERNCODE = '#sPattern#'
</cfquery>   

<cfset caller.Schedule = getSchedule>